import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'xtmh',
    component: () => import("../views/Xtmh")
  },
  {
    path: '/login',
    name: 'login',
    component: () => import("../views/Login")
  },
  {
    path: '/xmsy',
    name: 'xmsy',
    component: () => import("../views/Xmsy")
  },
  {
    path: '/design',
    name: 'design',
    component: () => import("../views/Design")
  },
  {
    path: '/doc',
    name: 'doc',
    component: () => import("../views/Doc")
  },
  {
    path: '/test',
    name: 'test',
    component: () => import("../views/Test")
  },
  {
    path: '*',
    redirect: "/"
  }
]

const router = new VueRouter({
  base: process.env.BASE_URL,
  routes
})

router.beforeEach(async (to, from, next) => {
  if (to.name === 'login') {
    return next();
  }
  let yhxx = mySessionStorage.getItem("yhxx");
  if (yhxx && yhxx.rybm) {
    return next();
  }
  // mySessionStorage.setItem("afterLogin", to.path)
  next("/login")
});

export default router
